﻿using Aker.DevTeam;
using DevExpress.XtraEditors;
using Extensions;
using System;
using System.Data;
using System.Windows.Forms;

namespace Aker.Hammadde
{
    public partial class HammaddeStok : XForm
    {
        public HammaddeStok()
        {
            InitializeComponent();
        }

        private void HammaddeStok_Load(object sender, EventArgs e)
        {
            DataSet ds = Data.DM.ExecuteDataSet("GetHammaddeStok", 1, DBNull.Value);

            ds.Relations.Add("Sipariş Detayı", ds.Tables[0].Columns["GrupKodu"], ds.Tables[1].Columns["GrupKodu"]);
            BindingSource bs = new BindingSource(ds, ds.Tables[0].TableName);
            BindingSource bsDetail = new BindingSource(bs, "Sipariş Detayı");

            gv.Init(bs);
            gv.ViewCaption = "Hammadde Stoğu (Grup+Tedarikçi+Renk)";
            gv.SetCaptions("HammaddeGrup:Hammadde Grubu", "Tedarikci:Tedarikçi", "CikisKG:Çıkılan KG", "GirisKG:Giriş KG", "CuvalBot:Çuval/Bot");
            gv.FormatAsNumber("GirisKG", "CikisKG", "Akfil", "Bilecik", "FiiliStok");
            gv.MakeColumnInvisible("GrupKodu");
            gv.AddSummary("CikisKG", "GirisKG", "CuvalBot", "LotAdedi", "Akfil", "Bilecik", "FiiliStok");
            gv.MakeReadOnly();
            gv.BestFitColumns();
            gv.EnableComplexFiltering("Grup");

            gvDetail.Init(bsDetail);
            gvDetail.ViewCaption = "Grup İçeriği";
            gvDetail.SetCaptions("CikisKG:Çıkılan KG");
            gvDetail.AddSummary("GirisKG", "CikisKG", "Akfil", "Bilecik", "FiiliStok");
            gvDetail.MakeColumnInvisible("HammaddeId", "GrupKodu");
            gvDetail.MakeReadOnly();

            gv.FocusedRowChanged += gv_FocusedRowChanged;
        }

        void gv_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gvDetail.BestFitColumns();
        }

        private void bbiDetay_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (splitter.PanelVisibility == SplitPanelVisibility.Both)
            {
                bbiDetay.Caption = "Detayları Göster";
                splitter.PanelVisibility = SplitPanelVisibility.Panel1;
            }
            else
            {
                splitter.PanelVisibility = SplitPanelVisibility.Both;
                bbiDetay.Caption = "Detayları Gizle";
            }
        }
    }
}
